package crawler.ctweb;

import crawler.BaseHibernateDAO;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for CtWeb
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see crawler.ctweb.CtWeb
 * @author MyEclipse Persistence Tools
 */

public class CtWebDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(CtWebDAO.class);
	// property constants
	public static final String CW_WEBURL = "cwWeburl";
	public static final String CW_WEBNAME = "cwWebname";
	public static final String CW_CTTYPE = "cwCttype";
	public static final String CW_CTTIME = "cwCttime";
	public static final String CW_WEBTYPE = "cwWebtype";
	public static final String CW_CTAREA_BEGIN = "cwCtareaBegin";
	public static final String CW_CTAREA_END = "cwCtareaEnd";
	public static final String CW_CTUSER = "cwCtuser";
	public static final String CW_PAGINATION = "cwPagination";
	public static final String CW_PAGETYPE = "cwPagetype";
	public static final String CW_INITPAGE = "cwInitpage";
	public static final String CW_FINISHPAGE = "cwFinishpage";
	public static final String CW_ISZEROS = "cwIszeros";
	public static final String CW_PAGEINCREMENTAL = "cwPageincremental";

	public void save(CtWeb transientInstance) {
		log.debug("saving CtWeb instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(CtWeb persistentInstance) {
		log.debug("deleting CtWeb instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public CtWeb findById(java.lang.String id) {
		log.debug("getting CtWeb instance with id: " + id);
		try {
			CtWeb instance = (CtWeb) getSession()
					.get("crawler.ctweb.CtWeb", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(CtWeb instance) {
		log.debug("finding CtWeb instance by example");
		try {
			List results = getSession().createCriteria("crawler.ctweb.CtWeb")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding CtWeb instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from CtWeb as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCwWeburl(Object cwWeburl) {
		return findByProperty(CW_WEBURL, cwWeburl);
	}

	public List findByCwWebname(Object cwWebname) {
		return findByProperty(CW_WEBNAME, cwWebname);
	}

	public List findByCwCttype(Object cwCttype) {
		return findByProperty(CW_CTTYPE, cwCttype);
	}

	public List findByCwCttime(Object cwCttime) {
		return findByProperty(CW_CTTIME, cwCttime);
	}

	public List findByCwWebtype(Object cwWebtype) {
		return findByProperty(CW_WEBTYPE, cwWebtype);
	}

	public List findByCwCtareaBegin(Object cwCtareaBegin) {
		return findByProperty(CW_CTAREA_BEGIN, cwCtareaBegin);
	}

	public List findByCwCtareaEnd(Object cwCtareaEnd) {
		return findByProperty(CW_CTAREA_END, cwCtareaEnd);
	}

	public List findByCwCtuser(Object cwCtuser) {
		return findByProperty(CW_CTUSER, cwCtuser);
	}

	public List findByCwPagination(Object cwPagination) {
		return findByProperty(CW_PAGINATION, cwPagination);
	}

	public List findByCwPagetype(Object cwPagetype) {
		return findByProperty(CW_PAGETYPE, cwPagetype);
	}

	public List findByCwInitpage(Object cwInitpage) {
		return findByProperty(CW_INITPAGE, cwInitpage);
	}

	public List findByCwFinishpage(Object cwFinishpage) {
		return findByProperty(CW_FINISHPAGE, cwFinishpage);
	}

	public List findByCwIszeros(Object cwIszeros) {
		return findByProperty(CW_ISZEROS, cwIszeros);
	}

	public List findByCwPageincremental(Object cwPageincremental) {
		return findByProperty(CW_PAGEINCREMENTAL, cwPageincremental);
	}

	public List findAll() {
		log.debug("finding all CtWeb instances");
		try {
			String queryString = "from CtWeb";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public CtWeb merge(CtWeb detachedInstance) {
		log.debug("merging CtWeb instance");
		try {
			CtWeb result = (CtWeb) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(CtWeb instance) {
		log.debug("attaching dirty CtWeb instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(CtWeb instance) {
		log.debug("attaching clean CtWeb instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}